﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;
using LTP.Accounts.Bus;
namespace Travel.Web.wb_users
{
    public partial class Modify : Page
    {       

        		protected void Page_Load(object sender, EventArgs e)
		{
			if (!Page.IsPostBack)
			{
				if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
				{
					string id= Request.Params["id"];
					ShowInfo(id);
				}
			}
		}
			
	private void ShowInfo(string id)
	{
		Travel.BLL.wb_users bll=new Travel.BLL.wb_users();
		Travel.Model.wb_users model=bll.GetModel(id);
		this.lblid.Text=model.id;
		this.txtusername.Text=model.username;
		this.txtpwd.Text=model.pwd;
		this.txtrealname.Text=model.realname;
		this.txtuser_type.Text=model.user_type.ToString();
		this.txtqq.Text=model.qq;
		this.txtemail.Text=model.email;
		this.txtphone.Text=model.phone;
		this.txtreg_time.Text=model.reg_time.ToString();
		this.txtlast_log_time.Text=model.last_log_time.ToString();
		this.txtlast_log_ip.Text=model.last_log_ip;
		this.txtuser_status.Text=model.user_status.ToString();

	}

		public void btnSave_Click(object sender, EventArgs e)
		{
			
			string strErr="";
			if(this.txtusername.Text.Trim().Length==0)
			{
				strErr+="用户名不能为空！\\n";	
			}
			if(this.txtpwd.Text.Trim().Length==0)
			{
				strErr+="密码不能为空！\\n";	
			}
			if(this.txtrealname.Text.Trim().Length==0)
			{
				strErr+="真实姓名不能为空！\\n";	
			}
			if(!PageValidate.IsNumber(txtuser_type.Text))
			{
				strErr+="会员类型 0普通会员格式错误！\\n";	
			}
			if(this.txtqq.Text.Trim().Length==0)
			{
				strErr+="QQ号码不能为空！\\n";	
			}
			if(this.txtemail.Text.Trim().Length==0)
			{
				strErr+="邮箱不能为空！\\n";	
			}
			if(this.txtphone.Text.Trim().Length==0)
			{
				strErr+="联系电话不能为空！\\n";	
			}
			if(!PageValidate.IsDateTime(txtreg_time.Text))
			{
				strErr+="注册时间格式错误！\\n";	
			}
			if(!PageValidate.IsDateTime(txtlast_log_time.Text))
			{
				strErr+="上次登录时间格式错误！\\n";	
			}
			if(this.txtlast_log_ip.Text.Trim().Length==0)
			{
				strErr+="上次登录ip不能为空！\\n";	
			}
			if(!PageValidate.IsNumber(txtuser_status.Text))
			{
				strErr+="用户状态格式错误！\\n";	
			}

			if(strErr!="")
			{
				MessageBox.Show(this,strErr);
				return;
			}
			string id=this.lblid.Text;
			string username=this.txtusername.Text;
			string pwd=this.txtpwd.Text;
			string realname=this.txtrealname.Text;
			int user_type=int.Parse(this.txtuser_type.Text);
			string qq=this.txtqq.Text;
			string email=this.txtemail.Text;
			string phone=this.txtphone.Text;
			DateTime reg_time=DateTime.Parse(this.txtreg_time.Text);
			DateTime last_log_time=DateTime.Parse(this.txtlast_log_time.Text);
			string last_log_ip=this.txtlast_log_ip.Text;
			int user_status=int.Parse(this.txtuser_status.Text);


			Travel.Model.wb_users model=new Travel.Model.wb_users();
			model.id=id;
			model.username=username;
			model.pwd=pwd;
			model.realname=realname;
			model.user_type=user_type;
			model.qq=qq;
			model.email=email;
			model.phone=phone;
			model.reg_time=reg_time;
			model.last_log_time=last_log_time;
			model.last_log_ip=last_log_ip;
			model.user_status=user_status;

			Travel.BLL.wb_users bll=new Travel.BLL.wb_users();
			bll.Update(model);
			Maticsoft.Common.MessageBox.ShowAndRedirect(this,"保存成功！","list.aspx");

		}


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx");
        }
    }
}
